package org.jsola.hr.helper;

import org.jsola.hr.dto.CrmCustomerImportRecordAddDTO;
import org.jsola.hr.dto.CrmCustomerImportRecordUpdateDTO;
import org.jsola.hr.entity.CrmCustomerImportRecordDO;
import org.jsola.hr.query.CrmCustomerImportRecordQuery;
import org.jsola.hr.service.ICrmCustomerImportRecordService;
import org.jsola.hr.vo.CrmCustomerImportRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 导入客户记录表
 *
 * @author zhr
 */
@Component
public class CrmCustomerImportRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmCustomerImportRecordService crmCustomerImportRecordService;

    /**
     * 生成add测试数据
     * @return CrmCustomerImportRecordAddDTO
     */
    public CrmCustomerImportRecordAddDTO getCrmCustomerImportRecordAddDTO(){
        CrmCustomerImportRecordAddDTO crmCustomerImportRecordAddDTO = new CrmCustomerImportRecordAddDTO();
        crmCustomerImportRecordAddDTO.setFileName(getRandomValue("varchar",32));
        crmCustomerImportRecordAddDTO.setDataType(getRandomValue("varchar",32));
        return crmCustomerImportRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmCustomerImportRecordUpdateDTO
     */
    public CrmCustomerImportRecordUpdateDTO getCrmCustomerImportRecordUpdateDTO(CrmCustomerImportRecordVO crmCustomerImportRecordVO){
        return crmCustomerImportRecordService.selectDOById(crmCustomerImportRecordVO.getId(), SITE_ID).to(CrmCustomerImportRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmCustomerImportRecordQuery
     */
    public CrmCustomerImportRecordQuery getCrmCustomerImportRecordQuery() {
        CrmCustomerImportRecordQuery crmCustomerImportRecordQuery = new CrmCustomerImportRecordQuery();
        List<CrmCustomerImportRecordDO> crmCustomerImportRecordDOList = crmCustomerImportRecordService.list(new CrmCustomerImportRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmCustomerImportRecordDOList)) {
            CrmCustomerImportRecordDO crmCustomerImportRecordDO = crmCustomerImportRecordDOList.get(0);
            crmCustomerImportRecordQuery = crmCustomerImportRecordDO.to(CrmCustomerImportRecordQuery.class);
        }
        return crmCustomerImportRecordQuery;
    }

    /**
     * 保存示例
     * @return CrmCustomerImportRecordVO
     */
    public CrmCustomerImportRecordVO saveCrmCustomerImportRecordExample(){
        CrmCustomerImportRecordAddDTO addDTO = this.getCrmCustomerImportRecordAddDTO();
        CrmCustomerImportRecordVO crmCustomerImportRecordVO = crmCustomerImportRecordService.save(addDTO,buildTokenUser());
        return crmCustomerImportRecordVO;
    }


}

